﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public static class DonVi_DB
    {
        public static DataTable SelectDV()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spSelectDV", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spSelectDV", con);
                cmd.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;

            }
        }
        public static void InsertDV(DonVi DV)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemDV", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spThemDV", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaDV", DV.MaDV);
                cmd.Parameters.AddWithValue("@TenDV", DV.TenDV);
                cmd.ExecuteNonQuery();
            }
        }

        public static void UpdateDV(DonVi DV)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatDV", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spCapNhatDV", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaDV", DV.MaDV);
                cmd.Parameters.AddWithValue("@TenDV", DV.TenDV);
                cmd.ExecuteNonQuery();
            }
        }

        public static void DeleteDV(DonVi DV)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaDV", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("spXoaDV", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MaDV", DV.MaDV);
                
                cmd.ExecuteNonQuery();
            }
        }
    }
}
